<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>住校审批</title>
    <link href="../../static/css/bootstrap.min.css" rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}">
    <!-- Custom styles for this template -->
    <link href="../../static/css/dashboard.css" rel="stylesheet" th:href="@{/static/css/dashboard.css}">
</head>
<body>
<div th:insert="admin/common::topbar"></div>
<div class="container-fluid">
    <div class="row">
        <div th:insert="~{admin/common::sidebar(active='operateDorm.html')}"></div>
        <main class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4" role="main">
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
                <h1 class="h3">编辑住校信息</h1>
                <div class="btn-toolbar mb-2 mb-md-0">
                    <div class="btn-group mr-2">
                        <button class="btn btn-sm btn-outline-secondary" id="btn-dorm">退出编辑</button>
                    </div>
                    <div class="btn-group mr-2">
                        <!--  -->
                        <button class="btn btn-primary btn-sm btn-outline-secondary" id="btn-admin">管理员</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-student">学生端</button>
                    </div>
                </div>
            </div>
            <form class="container-fluid col-md-5 col-md-pull-3" id="myForm" method="post"
                  th:action="@{/admin/editorStuDorm}">
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="sno">学号:</label>
                    <input class="form-control" id="sno" name="sno" readonly th:value="${student.getSno()}" type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="sname">姓名:</label>
                    <input class="form-control" id="sname" name="sname" readonly th:value="${student.getSname()}"
                           type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="sex">性别:</label>
                    <input class="form-control" id="sex" name="sex" readonly th:value="${student.getDorm_gender()}"
                           type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="dorm_id">宿舍:</label>
                    <select class="form-control" id="dorm_id" name="dorm_id">
                        <option th:each="dorm:${List}"
                                th:text="${dorm.getDormPlace()+'  '+dorm.getDorm_gender()+'寝  '+dorm.getDorm_number()+'人间'}"
                                th:value="${dorm.getDorm_id()}"></option>
                    </select>
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="bed_id">床位</label>
                    <input class="form-control" id="bed_id" name="bed_id" type="text">
                </div>
                <button class="btn btn-primary " id="button" type="submit">添加</button>
            </form>
        </main>
    </div>
</div>

<script src="../../static/js/jquery-3.6.0.min.js" th:src="@{/static/js/jquery-3.6.0.min.js}"
        type="text/javascript"></script>
<script src="../../static/js/bootstrap.min.js" th:src="@{/static/js/bootstrap.min.js}" type="text/javascript"></script>
<script>
    $(function () {
        let dormId = $('#dorm_id');
        let bedId = $('#bed_id');
        bedId.mouseout(function () {
            if (bedId.val() !== null && bedId.val() !== "") {
                $.get({
                    url: "/admin/ajax/getDorm",
                    data: {"dorm_id": dormId.val()},
                    success: function (dorm) {
                        if (dorm !== null) {
                            let number = dorm.dorm_number;
                            if (bedId.val() > number || bedId.val() < 1) {
                                alert("你输入的床位不合理!请重新输入");
                                bedId.val("");
                            } else {
                                $.get({
                                    url: "/admin/ajax/getStudentDorm",
                                    data: {"dorm_id": dormId.val(), "bed_id": bedId.val()},
                                    success: function (result) {
                                        if (result === false) {
                                            alert("该寝室床位已经有人登记注册了!请选择其他寝室床位!");
                                            bedId.val("");
                                        }
                                    }
                                })
                            }
                        }
                    }
                })
            }
        })
        $('#btn-dorm').click(function () {
            let result = confirm("是否退出编辑?");
            if (result === true) {
                $(location).attr('href', '/admin/getDormApplication');
            } else {

            }
        })
        $('#btn-admin').click(function () {
            let result = confirm("是否进入管理员登录?");
            if (result === true) {
                $(location).attr('href', '/adminLogin.html');
            } else {

            }

        })
        $('#btn-student').click(function () {
            let result = confirm("是否重新登录?");
            if (result === true) {
                $(location).attr('href', '/studentLogin.html');
            } else {

            }

        })
        $('#button').click(function () {
            let result = confirm("是否提交数据?");
            if (result === true) {
                $('#myForm').submit(function () {
                    alert("修改成功!");
                })
            }
        })
    })
</script>
</body>
</html>